var gulp = require('gulp');
var less = require('gulp-less');
var cssmin = require('gulp-minify-css'); //确保本地已安装gulp-minify-css [cnpm install gulp-minify-css --save-dev]
const babel = require('gulp-babel');

/**
 * 编译js
 */
gulp.task('es6', () =>
    gulp.src('src/assets/js/**/*.js')
    	.pipe(babel())
//      .pipe(babel({
//          presets: ['env']
//      }))
        .pipe(gulp.dest('dist/assets/js'))
);

/**
 * 复制js
 */
gulp.task('copyJS', function () {
    return gulp.src('src/assets/js/**/*.js')
        .pipe(gulp.dest('dist/assets/js'))
});

/**
 * 编译less
 */
gulp.task('less', function () {
    gulp.src(['src/assets/less/**/*.less'])
        .pipe(less())
        .pipe(cssmin()) //兼容IE7及以下需设置compatibility属性 .pipe(cssmin({compatibility: 'ie7'}))
        .pipe(gulp.dest('dist/assets/css'));
});

gulp.task('default',function () {
    gulp.watch(['src/assets/less/**/*.less'], ['less']); //当所有less文件发生改变时，调用testLess任务
    // gulp.watch(['src/assets/js/**/*.js'], ['copyJS']);
    gulp.watch(['src/assets/js/**/*.js'], ['es6']);
});